class Solution(object):
    def minDistance(self, height, width, tree, squirrel, nuts):
        """
        :type height: int
        :type width: int
        :type tree: List[int]
        :type squirrel: List[int]
        :type nuts: List[List[int]]
        :rtype: int
        """
        total = 0
        save = -float('inf')
        for nut in nuts:
            nut_tree = abs(nut[0] - tree[0]) + abs(nut[1] - tree[1])
            nut_s = abs(nut[0] - squirrel[0]) + abs(nut[1] - squirrel[1])
            save = max(save, nut_tree - nut_s)
            total += 2 * nut_tree
        return total - save

